home *** CD-ROM | disk | FTP | other *** search
- Path: sooner.net!usenet
- From: Eddie Bush <edwbush@sooner.net>
- Newsgroups: comp.lang.c
- Subject: Passing Function Pointers
- Date: Sun, 31 Mar 1996 03:54:44 -0800
- Organization: sooner.net news site
- Message-ID: <315E7284.479F@sooner.net>
- NNTP-Posting-Host: p28.sooner.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- I have a segment of code that is meant to delete a node out of a linked
- list [type *list - this instance is *my_list]. The deal is, I am
- structuring this somewhat in a database form. I am building this ADT
- (priority queue), and want the user to be able to do whatever they wish
- with the node being deleted. I couldn't think of any way to pass the
- node back to the calling function, so, instead, I decided that I would
- allow the user to pass in a function and then call that function inside
- the delete function - using the soon to be deleted node as a parameter.
- This way, the user can do whatever they want with the node, and I don't
- have to worry about passing it back to the calling function.
- I have used this technique under UN*X platforms using gcc to compile, and
- it works just fine. It has been a while since I've done it though, so I
- am thinking that maybe it is not just perfectly correct or something.
- Anyhow, here it is:
-
- void delete (list *my_list, int *fn){
-
- l_node temp_node = (*my_list) -> head;
-
- if (!is_empty(*my_list)){
- (*my_list) -> head = (*my_list) -> head -> next;
- (*my_list) -> head -> pre = NULL;
- }
- (*fn) (temp_node);
- free (temp_node);
- }
-
- I made *fn an int because it didn't like the void, and now instead of
- complaining about that it complains about - well, here's the error
- message:
-
- Error LIST.H 71: Call to nonfunction.
-
- Any ideas? It isn't 'clicking' for me. Is this something to do with the
- version (Borland C/C++ 3.0) I am running maybe? I passed pointers to
- functions fine using the gcc compiler!
-
- Anything would be appreciated!
-
- Thanx in Advance!
-
- Eddie Bush
-